<template>
  <div class="bg-detail">
    <el-dialog :visible.sync="centerDialogVisible" width="60%"
    :modal-append-to-body="false"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :show-close="false">
      <div class="bg-info">
        <div class="item-img">
          <img :src="imgUrl" alt="" srcset="">
        </div>
        <div class="item-info">
          <p>{{ item.name }}</p>
          <p>1920px*1080px</p>
          <p>{{ item.startTime | dateFormat('')}}-{{ item.endTime | dateFormat('') }}</p>
          <div>
            <el-button style="background: #4065E0; color: #fff" @click="define">启用</el-button>
            <el-button style="background: #EEEEEE; color: #333333" @click="cancel">取消</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { setActiveBg } from 'api/backgroundController/backgroundController'
export default {
  name: "BgDetail",
  props: {
    item: {
      type: Object,
      default: {}
    },
    moduleId: {
      type: Number
    },
    appId: {
      type: String
    }
  },
  data() {
    return {
      centerDialogVisible: true,
    };
  },
  computed: {
    imgUrl: function(){
      return this.item.image
    },
    // startTime: function(){
    //   return
    // },
    // endTime: function(){

    // }
  },
  methods: {
    cancel() {
        this.$emit("sendState", false);
    },
    define(){
        // 请求接口，拿到预设的时间传给后台
        var params = {
          appId: this.appId,
          bgId: this.item.bgId,
          moduleId: this.moduleId
        }
        setActiveBg(params).then(res => {
          if(res.resultCode == 1){
            this.$message.success(res.resultMsg)
            this.$emit("sendState", false);
          }else{
            this.$message.error(res.resultMsg)
          }
        })
        .catch(res => {
          this.$message.error('服务器异常')
        })
    },
    // 选择的时间
   
  }
};
</script>

<style lang="scss" scoped>
.bg-detail {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  .bg-info{
    display: flex;
    justify-content: space-between;
    .item-img{
      width: 270px;
      height: 440px;
      margin-right: 20px;
      img{
        width: 100%;
        height: 100%;
      }
    }
    .item-info{
      p{
        margin-bottom: 20px;
        &:nth-of-type(1){
          font-size: 18px;
          font-weight: 600;
          color: #333333;
        }
        &:nth-of-type(2){
          color: #333333;
        }
        &:nth-of-type(3){
          color: #666666;
          font-size: 12px;
        }
      }
    }
  }
  
  .el-button+.el-button{
      margin-left: 30px;
  }
}
</style>
